<template>
  <div class="menu">
    <div class="item" v-for="(menu, index) in menuList" :key="index"
                :class="{selected : index === selectedItem}"
                @click="()=>{selectItem(index),navigateTo(menu.route)}">
      <div class="icon-container">
        <el-image :src="require(`@/assets/menu/${menu.name}`)" />
      </div>
      <div class="icon-name">
        <span>{{ menu.character }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ElImage } from 'element-plus';
import {ref} from "vue";
import {useRouter} from "vue-router";
const router = useRouter();

const menuList = ref([
  { name: "coin.svg", character: "法币交易" ,route:'/transaction'},
  { name: "dropbox.svg", character: "理财宝",route:'/money' },
  { name: "globe.svg", character: "StarUp首发",route:'/startup' },
  { name: "app.svg", character: "MiNiApp" ,route: 'miNiApp'},
  { name: "cash-coin.svg", character: "余额宝",route: 'yueBao' },
  { name: "piggy-bank-fill.svg", character: "财富管理",route: '/wealthManage' },
  { name: "bar-chart-fill.svg", character: "量化限单",route:'/quantitative' },
  { name: "app-indicator.svg", character: "大数据",route: 'bigData' },
  { name: "safe-fill.svg", character: "NFT" ,route: '/NFT'},
  { name: "three-dots.svg", character: "更多" ,route: '/more'}
]);
const selectedItem = ref(-1);
function selectItem(index){
  selectedItem.value = index;
}
function navigateTo(route){
  router.push(route)
}
</script>

<style scoped>
.menu {
  width: 100%;
  margin-top: 50px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.item:hover {
  background-color: #3373CC; /* 鼠标悬停时的背景色 */
}
.selected {
  background-color: #275B9B; /* 选中时的背景色 */
}
.item {
  width: 24%;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #409EFF;
  padding: 10px 0;
}
.icon-container {
  width: 50px;
  height: 50px;
}
.el-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.icon-name {
  text-align: center;
  margin-top: 5px;
}
</style>